<?php

namespace addons\sumprint;

use app\common\library\Menu;
use think\Addons;
use think\Loader;

/**
 * 插件
 */
class Sumprint extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'sumprint',
                'title'   => '打印管理',
                'icon'    => 'fa fa-print',
                'sublist' => [
                    [
                        'name'    => 'sumprint/printer',
                        'title'   => '打印机管理',
                        'icon'    => 'fa fa-print',
                        'sublist' => [
                            ['name' => 'sumprint/printer/index', 'title' => '查看'],
                            ['name' => 'sumprint/printer/detail', 'title' => '详情'],
                            ['name' => 'sumprint/printer/change', 'title' => '变更'],
                            ['name' => 'sumprint/printer/del', 'title' => '删除'],
                            ['name' => 'sumprint/printer/multi', 'title' => '批量更新'],
                        ]
                    ],
                    [
                        'name'    => 'sumprint/template',
                        'title'   => '模版管理',
                        'icon'    => 'fa fa-delicious',
                        'sublist' => [
                            ['name' => 'sumprint/template/index', 'title' => '查看'],
                            ['name' => 'sumprint/template/detail', 'title' => '详情'],
                            ['name' => 'sumprint/template/change', 'title' => '变更'],
                            ['name' => 'sumprint/template/del', 'title' => '删除'],
                            ['name' => 'sumprint/template/multi', 'title' => '批量更新'],
                        ]
                    ],

                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('sumprint');
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable('sumprint');
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable('sumprint');
        return true;
    }
    /**
     * 添加命名空间
     */
    public function appInit()
    {
        //添加命名空间
        if (!class_exists('App\Config\YlyConfig')) {
            Loader::addNamespace('App\Config', ADDON_PATH . 'sumprint' . DS . 'library' . DS . 'yly-openapi' . DS . 'Config' . DS);
        }
        if (!class_exists('App\Oauth\YlyOauthClient')) {
            Loader::addNamespace('App\Oauth', ADDON_PATH . 'sumprint' . DS . 'library' . DS . 'yly-openapi' . DS . 'Oauth' . DS);
        }
        if (!class_exists('App\Api\PrintService')) {
            Loader::addNamespace('App\Api', ADDON_PATH . 'sumprint' . DS . 'library' . DS . 'yly-openapi' . DS . 'Api' . DS);
        }
        if (!class_exists('App\Protocol\YlyRpcClient')) {
            Loader::addNamespace('App\Protocol', ADDON_PATH . 'sumprint' . DS . 'library' . DS . 'yly-openapi' . DS . 'Protocol' . DS);
        }

    }
}
